package com.pz.gulimall.product.controller;

import com.pz.gulimall.common.to.ShopCarItemTo;
import com.pz.gulimall.common.utils.PageUtils;
import com.pz.gulimall.common.utils.R;
import com.pz.gulimall.product.service.ShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("product/shopcar")
public class ShopCarController {
    @Autowired
    private ShopCarService shopCarService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = shopCarService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody List<ShopCarItemTo> shopcarItems){
        shopCarService.saveItems(shopcarItems);
        return R.ok();
    }

    @GetMapping("/query/{loginId}")
    public R getByLoginId(@PathVariable String loginId){
        return shopCarService.queryByLoginId(loginId);
    }

    @PostMapping("/query/batch")
    public R queryBatch(@RequestBody List<String> loginIds){
        return shopCarService.queryBatchByLoginIds(loginIds);
    }

    @GetMapping("/del/{loginId}")
    public R del(@PathVariable String loginId, @RequestBody List<Long> skuId){
        return shopCarService.delItems(loginId, skuId);
    }
}
